<?php 

require_once('../include/GeneralTop.php');
require('../include/class/db.php');
require('../include/class/pagination.php');

if (!$content_admin) {
	die('<div style="text-align:center">Permission denied...</div>');
}

$db = new db;

$all = array();
$sql = "select batch from newsletter_log where id='".$_GET['id']."'";
$res = $db->query($sql);
$row = $db->fetch($res);
$filename = NEWSLETTER_LOG_MAIL_ADDRESS_PATH.'/'.$row['batch'].'_failed';
$content = unserialize(file_get_contents($filename));
if ((isset($_GET['email'])) && ($_GET['email'] != "")) {
	foreach($content as $_key => $_value) {
		if($_GET['email'] == $_value['email'] && $_GET['name'] == $_value['name']) {
			//remove;
		}
		else {
			$all[] = array('name' => $_value['name'],
		    		   	   'email' => $_value['email'],
		    		   	   'status' => 0);
		}
	}
	file_put_contents($filename, serialize($all));
}
else {
	$all = $content;
}

$sel = array();
foreach($all as $_key => $_value) {
	if(isset($_GET['kw']) && '' != $_GET['kw']) {
		if($_GET['kw'] == $_value['email']) {
			$sel[] = array('name' => $_value['name'],
	    		   		   'email' => $_value['email'],
	    		   		   'status' => 0);
		}
	}
	else {
		$sel[] = array('name' => $_value['name'],
	    		   	   'email' => $_value['email'],
	    		   	   'status' => 0);
	}
}

include('AdminPanel.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../Felix_css.css" rel="stylesheet" type="text/css" />
<title>Newsletter log</title>
</head>

<body>
<table width="60%" border="0" align="center" cellpadding="5" cellspacing="0" class="table_border_grey" style="margin-top:10px;">
  <tr>
    <td colspan="3">
	  <form action="<?php echo $_SERVER['PHP_SELF']?>" method="GET">
	  Search sent newsletters： <input type="text" name="kw" size="20">
	  <input type="hidden" name="id" value="<?php echo $_GET['id']?>">
	  <input type="submit" name="submit" id="submit" value=" Search title "> 
	  <input type="button" id="button" onclick="window.location.href='NewsletterLog.php'" value=" Back ">
	  </form>
	</td>
  </tr>
  <tr>
    <td width="25%">&nbsp;</td>
    <td width="50%">Email</td>
    <td width="25%">name</td>
  </tr>
    <?php
	$num = count($all);
	if($num > 0) {
		foreach($all as $_key => $_value) {
    ?>
    <tr>
      <td>
        <label>
          <input type="button" name="button" id="button" value="Remove from resend query" onclick="if(confirm('Are you sure to remove it from resend query?')){window.location.href='<?php echo $_SERVER['PHP_SELF']?>?email=<?php echo $_value['email'] ?>&name=<?php echo $_value['name'] ?>&id=<?php echo $_GET['id']?>'}"/>
        </label>
      </td>
      <td><?php echo $_value['email'] ?></td>
      <td><?php echo $_value['name'] ?></td>
    </tr>
    <?php
		}
	}
	?>
	<tr>
    <td colspan="3">
	    <?php
		if($num > PAGICATION_RECORD_COUNT_NEWS) {
			echo $pagination->paginationString;
		}
		?>
	</td>
  </tr>
</table>
<br />
</body>
</html>